<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class ProjectAttach_model extends CI_Model {
    
    public $tablename = 'hpg_project_attach';
    
    public function __construct()
    {
        parent::__construct();
    }
    
    public function insertBatch($list){
        if( !$list ){
            return false;
        }
        $res = $this->db->insert_batch($this->tablename, $list);
        return $res;
    }
    
    public function getAttachList($project_id, $fields){
        if( !$project_id ){
            return false;
        }
        $query = $this->db->from($this->tablename)->select('attach_id,field,filename,url,size,ext')->where('project_id', $project_id);
        if( $fields ){
            $query->where_in('field', $fields);
        }
        $result = $query->get_array();
        $tmpdata = [];
        if( $result ){
            foreach($result as $v){
                $v['url'] = 'http://'.$_SERVER['HTTP_HOST'].'/uploads/'.$v['url'];
                $tmpdata[$v['field']][] = $v;
            }
        }
        return $tmpdata;
    }
    
    public function delete_attach_in($ids){
        if( !$ids ){
            return false;
        }
        $res = $this->db->from($this->tablename)->where_in('attach_id', $ids)->delete();
        return $res;
    }
}
?>